// pages/orderDetail/orderDetail.js
const app = getApp();
var network = require("../../utils/request.js")
Page({

  /**
   * 页面的初始数据
   */
  data: {
    list:[],
    is_iphonex:false,
    showDemand:false,
    popleNum:0,
    status:null,
    chooseCommentType:null,
    statusText:'',
    screenIndex:null,
    showScreen:false,
    timeStr:'29:00',
    showCancelRecords:false,
    obj:'',
    mineData:[],
    personData:[],
    sortField: 'C_TIME',//C_TIME、C_PRICE 按时间 按价格
    style:'asc',//asc、desc
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var obj = JSON.parse(options.obj)
    obj.time1 = ((obj.time).split(','))[0]
    obj.time2 = ((obj.time).split(','))[1]
    let status = obj.status
    console.log(obj)
    this.setData({
      obj: obj
    })
    this.getMineReciveList(obj.id);
    this.getOfferInfoIntentional(obj.id);

    if(status != null){
      this.setData({
        status:status,
        statusText: this.getStatusText(status)
      })
    }
    if(status == 0){
      this.setData({
        list:list
      })     
    } else if (status == 4){
      this.payTimeInterVal()
    }
    var res = wx.getSystemInfoSync()
    console.log(res)
    this.setData({
      windowHeight: res.windowHeight
    })
  },

  //需求详情
  getMineReciveList: function (id) {
    var that = this;
    network.requestLoading('POST', app.globalData.requestUrl + 'getDemandInfoByDemandIdAPI',
      {
        consumerId: app.globalData.consumerid,
        demandId: id
      }, '加载中', function (res) {
        that.setData({
          mineData: res.data
        })
      })
  },

  //意向人列表
  getOfferInfoIntentional:function(id){
      var that = this;
    network.requestLoading('POST', app.globalData.requestUrl + 'getOfferInfoIntentionalReceiverSortAPI',
        {
          demandId: id,
          sortField: that.data.sortField,
          style: that.data.style
        }, '加载中', function (res) {
          that.setData({
            personData: res.data
          })
          
      })
  },
  chooseCommentType:function(e){
    this.setData({
      chooseCommentType:e.currentTarget.dataset.index
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },
  showDemand:function(){
    this.setData({
      showDemand: !this.data.showDemand
    })
  },
  showCancelRecords:function(){
    console.log(111)
    this.setData({
      showCancelRecords: !this.data.showCancelRecords
    })
  },
  screen: function () {
    this.setData({
      showScreen: !this.data.showScreen
    })
  },
  payTimeInterVal:function(){
    var that = this
    console.log(payTime)
    var payTimeInterVal = setInterval(function(){
      --payTime
      if (payTime < 1){
        clearInterval(payTimeInterVal)
        return false
      }
      var minute = Math.floor(payTime / 60)
      var second = payTime % 60
      that.setData({
        timeStr: minute + ':' + second
      })
    },1000)
  },
  screenChange: function (e) {
    var index = e.currentTarget.dataset.index
    if (index == this.data.screenIndex) {
      this.setData({
        screenIndex: null
      })
      console.log('取消当前选中')
      return false
    }
    this.setData({
      screenIndex: index
    })
    console.log(index==0?'使用积分':'使用现金')
  },
  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },
  getStatusText:function(status){
    if (status == 0) return '未接单'
    if (status == 1) return '办理中'
    if (status == 2) return '已完成(未确认)'
    if (status == 3) return '已结束'
    if (status == 4) return '已接单(未支付)'
  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})